<?php 
namespace app\superadmin\controller;
use think\Db;
use think\Controller;
class Newer extends Base{
	public function index(){
		$advers=Db::name("adver")->alias('a')->join('videos v','a.vid=v.vid')->join('videotype t','v.tid=t.tid')->select();
		$this->assign('advers',$advers);
		return $this->fetch();
	}

	//修改广告页
	public function changeadver($aid){
		$types=Db::name('videotype')->select();
		$datas=Db::name('adver')->where('aid',$aid)->select();
		$this->assign('datas',$datas);
		$this->assign('types',$types);
		return $this->fetch();
	}

	//ajax
	public function show(){
		// $data=input("post.");
		$tid=input("tid");
		$vname=input("vname");
		$aid=input("aid");
		$datas=Db::name('videos')->where('tid',$tid)->where('videoname','like','%'.$vname.'%')->where("vstatus='0'")->select();
		// return json($datas);
		$output='';
		foreach ($datas as $i) {
			# code...
			$output.="<div id=\"user\">
						<a href=\"".url('change',['vid'=>$i['vid'],'aid'=>$aid])."\"><img src=\"".PIC_PATH.$i['pic']."\"  width=\"150\" height=\"150\"/></a>
						<p class=\"zzz\">视频名：".$i['videoname']."</p>
						<p class=\"zzz\">上传人：".$i['uploadadmin']."</p>
					</div>";
		}
		echo $output;
	}
	public function change(){
		// dump();
		$vid=input("vid");
		$aid=input("aid");

		// dump($vid);
		// dump($aid);
		$res=Db::name('adver')->where('aid',$aid)->update(['vid'=>$vid]);
		if ($res) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('修改失败！');
		}

	}
}